import { streamText } from 'ai'
import { createDeepSeek } from '@ai-sdk/deepseek';
export default defineLazyEventHandler(async () => {
    const apiKey = useRuntimeConfig().openaiApiKey;
    if (!apiKey) throw new Error('Missing OpenAI API key');
    const deepseek = createDeepSeek({
        apiKey: apiKey,
    });
    return defineEventHandler(async (event: any) => {
        const { messages } = await readBody(event);

        console.log("messages", messages);

        const result = streamText({
            model: deepseek('deepseek-chat'),
            messages
        })
        const res = result.toDataStreamResponse()
        console.log("res", res);

        return res
    });
});